package com.study.kafkademo.controller;

import com.study.kafkademo.kafka.custom.CustomKafkaProducer;
import com.study.kafkademo.kafka.custom.model.KafkaMessage;
import com.study.kafkademo.kafka.custom.model.KafkaMessageHeader;
import com.study.kafkademo.kafka.custom.model.MsgTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("/custom/kafka")
public class CustomkafkaController {

    @Autowired
    private CustomKafkaProducer customKafkaProducer;

    @GetMapping(value = "/send")
    public void sendMsg() {

        for (int i = 0; i < 50; i++) {
            KafkaMessageHeader header = new KafkaMessageHeader();
            header.setSerialNo(UUID.randomUUID().toString());
            header.setSystemSourceId(i + "");
            header.setMessageType("type");
            header.setCreateTime(new Date());
            //
            KafkaMessage message = new KafkaMessage();
            message.setMessageHeader(header);

            MsgTemplate msgTemplate = new MsgTemplate();
            msgTemplate.setMsg("消息 +" + i);
            msgTemplate.setTitle("不知");
            msgTemplate.setId("id-" + i);
            message.setDate(msgTemplate);

            //发送
            customKafkaProducer.sendMessge(CustomKafkaProducer.TOPIC_TEST, message);
        }
    }
}
